<?php


namespace Home\Controller;
use Think\Controller;
class BusinessController extends CommonController {

	public function detail(){
		$data['id']=$_SESSION['uid'];
		$info=M('business')->where($data)->find();
		$info['business_photos']=explode('|', $info['business_photos']);
		foreach($info['business_photos'] as $k=>$v){
			$info['business_photos'][$k]=C('URL').$v;
		}
		$info['business_licence']=C('URL').$info['business_licence'];
		$info['business_picture']=C('URL').$info['business_picture'];
		$this->assign('info',$info);
		$this->display();
	}

	public function edit(){
		$data['id']=I('post.business_id','');
		$data['customer_tel']=I('post.customer_tel','');
		$data['business_notes']=I('post.business_notes','');
		$data['business_scope']=I('post.business_scope','');
		$data['business_others']=I('post.business_others','');
		$data['business_describe']=I('post.business_describe','');
		$data['business_address']=I('post.business_address','');
		$data['update_time']=time();
		if(empty($data['customer_tel'])){
			die(json_error('客服电话不能为空！'));
		}
		if(empty($data['business_notes'])){
			die(json_error('购买须知不能为空！'));
		}
		if(empty($data['business_scope'])){
			die(json_error('配送范围不能为空！'));
		}
		if(empty($data['business_others'])){
			die(json_error('其他说明不能为空！'));
		}
		if(empty($data['business_describe'])){
			die(json_error('商家描述不能为空！'));
		}
		if(empty($data['business_address'])){
			die(json_error('商家地址不能为空！'));
		}
		$res=M('business')->save($data);
		if($res){
			$this->success('保存成功');
		} else{
			$this->error('保存失败');
		}
	}

}